﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Triunfadores.BusinessEntities;

namespace Triunfadores.Repository.Mapping
{
    public class DetalleVentaAccionMap:EntityTypeConfiguration<DetalleVentaAccion>
    {
        public DetalleVentaAccionMap()
        {
            //primary key
            this.HasKey(t => new { t.VentaAccId, AccionId = t.AccionId });

            //properties
            this.Property(t => t.VentaAccId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
            this.Property(t => t.AccionId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Cantidad)
                .HasColumnType("int")
                .IsRequired();
            this.Ignore(p => p.Monto);

            //relationships
            this.HasRequired(t => t.VentaAccion)
                .WithMany(t => t.VentaAccionDetalles)
                .HasForeignKey(d => d.VentaAccId)
                .WillCascadeOnDelete(true);

            this.HasRequired(t => t.Accion)
                .WithMany()
                .HasForeignKey(d => d.AccionId)
                .WillCascadeOnDelete(false);
            
        }
    }
}
